package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.domain.ZhDeptInfo;
import com.ruoyi.system.domain.ZhWaiter;
import com.ruoyi.system.service.ISysPostService;
import com.ruoyi.common.service.IZhDeptInfoService;
import com.ruoyi.system.service.IZhWaiterService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客服 信息操作处理
 *
 * @author ruoyi
 * @date 2019-04-26
 */
@Controller
@RequestMapping("/system/zhWaiter")
public class ZhWaiterController extends BaseController {
    private String prefix = "system/zhWaiter";

    @Autowired
    private IZhWaiterService zhWaiterService;


    @Autowired
    private IZhDeptInfoService zhDeptInfoService;

    @RequiresPermissions("system:zhWaiter:view")
    @GetMapping()
    @DataScope(tableAlias = "l")
    public String zhWaiter(ZhDeptInfo zhDeptInfo, ModelMap mmap) {
        mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(zhDeptInfo));
        return prefix + "/zhWaiter";
    }

    /**
     * 查询客服列表
     */
    @DataScope(tableAlias = "l")
    @RequiresPermissions("system:zhWaiter:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZhWaiter zhWaiter,ModelMap mmap) {

        startPage();
        List<ZhWaiter> list = zhWaiterService.selectZhWaiterList(zhWaiter);
        mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhWaiter.getParams())));
        return getDataTable(list);
    }


    /**
     * 导出客服列表
     */
    @RequiresPermissions("system:zhWaiter:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhWaiter zhWaiter) {
        List<ZhWaiter> list = zhWaiterService.selectZhWaiterList(zhWaiter);
        ExcelUtil<ZhWaiter> util = new ExcelUtil<ZhWaiter>(ZhWaiter.class);
        return util.exportExcel(list, "zhWaiter");
    }

    /**
     * 新增客服
     */
    @DataScope(tableAlias = "l")
    @GetMapping("/add")
    public String add(ZhDeptInfo zhDeptInfo,ModelMap mmap) {
        mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhDeptInfo.getParams())));
        return prefix + "/add";
    }

    /**
     * 新增保存客服
     */
    @RequiresPermissions("system:zhWaiter:add")
    @Log(title = "客服" , businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZhWaiter zhWaiter) {
        return toAjax(zhWaiterService.insertZhWaiter(zhWaiter));
    }

    /**
     * 修改客服
     */
    @Autowired
    private ISysPostService postService;

    @DataScope(tableAlias = "l")
    @GetMapping("/edit/{id}")
    public String edit(ZhDeptInfo zhDeptInfo,
                       @PathVariable("id") Integer id,
                       ModelMap mmap) {
        ZhWaiter zhWaiter = zhWaiterService.selectZhWaiterById(id);

        mmap.put("zhWaiter" , zhWaiter);
        mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhDeptInfo.getParams())));

        return prefix + "/edit";
    }

    /**
     * 修改保存客服
     */
    @RequiresPermissions("system:zhWaiter:edit")
    @Log(title = "客服" , businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZhWaiter zhWaiter) {
        return toAjax(zhWaiterService.updateZhWaiter(zhWaiter));
    }

    /**
     * 删除客服
     */
    @DataScope(tableAlias = "l")
    @RequiresPermissions("system:zhWaiter:remove")
    @Log(title = "客服" , businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(ZhWaiter zhWaiter,String ids) {
        return toAjax(zhWaiterService.deleteZhWaiterByIds(ids));
    }

}
